package com.carsystem.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.carsystem.entity.TReturncar;
import com.carsystem.mapper.TReturncarMapper;
import com.carsystem.request.ReturnCarRequestVo;
import com.carsystem.response.OrderResponseVo;
import com.carsystem.response.ReturnCarResponseVo;
import com.carsystem.service.ITReturncarService;
import com.carsystem.utils.MessageConstant;
import com.carsystem.utils.PageHandler;
import com.carsystem.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ykl
 * @since 2022-03-25
 */
@Service
public class TReturncarServiceImpl extends ServiceImpl<TReturncarMapper, TReturncar> implements ITReturncarService {

    @Resource
    private TReturncarMapper returncarMapper;

    @Override
    public PageHandler selectReturnByPage(ReturnCarRequestVo returnCarRequestVo) {
        Map<String, Object> map = new HashMap<>();
        Integer offset = (returnCarRequestVo.getPageIndex() - 1) * returnCarRequestVo.getPageSize();
        map.put("offset",offset);
        map.put("pageSize", returnCarRequestVo.getPageSize());
        if (StringUtils.isNotBlank(returnCarRequestVo.getOrderId())){
            map.put("orderId",returnCarRequestVo.getOrderId());
        }
        if (StringUtils.isNotBlank(returnCarRequestVo.getMemberName())){
            map.put("memberName",returnCarRequestVo.getMemberName());
        }
        if (StringUtils.isNotBlank(returnCarRequestVo.getPhoneNumber())){
            map.put("phoneNumber",returnCarRequestVo.getPhoneNumber());
        }
        if (StringUtils.isNotBlank(returnCarRequestVo.getCarName())){
            map.put("carName",returnCarRequestVo.getCarName());
        }
        if (StringUtils.isNotBlank(returnCarRequestVo.getReturnStartDate())){
            map.put("returnStartDate",returnCarRequestVo.getReturnStartDate());
        }
        if (StringUtils.isNotBlank(returnCarRequestVo.getReturnEndDate())){
            map.put("returnEndDate",returnCarRequestVo.getReturnEndDate());
        }
        Integer count = returncarMapper.getReturnCarListCount(map);
        List<ReturnCarResponseVo> orderList = returncarMapper.getReturnCarList(map);
        PageHandler pageHandler = new PageHandler(returnCarRequestVo.getPageIndex(), returnCarRequestVo.getPageSize(),count);
        pageHandler.setList(orderList);
        return pageHandler;
    }

    @Override
    public Result returnUpload(TReturncar returncar) {
        boolean returnCar = returncarMapper.returnUpload(returncar);
        if (returnCar){
            return new Result(true, "上传成功");
        }
        return new Result(false,"上传失败");
    }
}
